<?php

namespace app\admin\validate;

use app\admin\model\UserModel;
use think\Validate;

class UserForm extends Validate
{

    protected $rule = [
        'nickname|昵称' =>'require|max:100',
        'email|邮箱' =>'require|max:60|email',
        'password|登录密码' =>'require|max:128',
        'telephone|手机号码' =>'require|number|mobile|max:12',
        'sex|性别' =>'require|in:男,女,未知',
        'agent_grade|代理等级' =>'require|number|max:1',
        'lock|状态' =>'require|number|max:1',
        'true_name|真实姓名' =>'require|max:10|chs',
        'IDCard|身份证号' =>'require|max:18|idCard',
        'alipay|支付宝账号' =>'max:60',
        'operate_id|运营中心id' =>'require|number|max:11',
        'operate_name' =>'max:200',
        'address|注册地址' =>'require|max:120',
        'is_salesman|是否是业务员' =>'require|number|max:1',
        'parent_id|上级用户id' =>'number|max:11',
        'authorization_code|授权编号' =>'max:60',
        'number|联通工号' =>'max:60',
    ];
    public function add($array){
        require_once  mooshroom;
        $hashObj = new \mooshroom\details\crypt\Hash();
        $array['password'] =  $hashObj->Encryption(md5($array['password']));
        $info =  (new UserModel())->isAutoWriteTimestamp('datetime')->allowField(true)->save($array);
         UserModel::where('id',$array['parent_id'])->setInc('recommend_number');
        return $info;
    }
}